import pandas as pd
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['STHeiti', 'PingFang SC', 'Heiti TC', 'Microsoft YaHei', 'SimHei', 'Arial Unicode MS']  
plt.rcParams['axes.unicode_minus'] = False

# 构建 DataFrame（你也可以用 pd.read_csv 读取文件）
data = {
    "scenario": ["fix", "v1g", "v2g"],
    "2025": [4850, 4824, 4753],
    "2030": [5902, 5810, 5725],
    "2035": [6974, 6772, 6683],
    "2040": [8577, 8200, 8102],
    "2045": [9880, 9310, 9256],
    "2050": [11817, 11060, 10788]
}
df = pd.read_csv("data-3-1.csv").set_index("scenario")
df.index = ["NC-LOW-UC", "NC-LOW-V1G", "NC-LOW-V2G"]

# 配色
colors = {
    "NC-LOW-UC": "#a6eb9a",
    "NC-LOW-V1G": "#f2a93b",
    "NC-LOW-V2G": "#685cc6"
}

# 标记样式（可以根据需要自定义）
markers = {
    "NC-LOW-UC": "o",
    "NC-LOW-V1G": "o",
    "NC-LOW-V2G": "o"
}

# 画图
plt.figure(figsize=(5, 4))
years = df.columns.astype(int)

for scenario in reversed(df.index):
    plt.scatter(years, df.loc[scenario], label=scenario,
                color=colors[scenario], marker=markers[scenario], s=50)

plt.xlabel("Year", fontsize=12)
plt.ylabel("CO2 Emissions (100M tons)", fontsize=12)
# plt.ylim(4000, 13000)
# plt.title("不同情景下的数值变化", fontsize=14)
plt.xticks(years)

# 手动排序 legend 顺序
handles, labels = plt.gca().get_legend_handles_labels()
ordered_labels = list(df.index)  # 正常顺序
ordered_handles = [handles[labels.index(lbl)] for lbl in ordered_labels]
plt.legend(ordered_handles, ordered_labels)
# plt.legend()
# plt.grid(True, linestyle="--", alpha=0.5)
plt.tight_layout()
plt.show()
